<?php

/**
 * Subclass for representing a row from the 'invoice' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Invoice extends BaseInvoice
{
  function Invoice(){
    $this->setInvoiceIden('');
    $this->setCustomerIden('');
    $this->setInvoiceType('');
    $this->setInvoiceId('');
    $this->setDeliveryDate(date('m/d/y'));
    $this->setTermsName('');
    $this->setDaysDue(0);
    $this->setRemarks('');
    $this->setVatExcemptType('');
  }
  
  public function getTotal(){
    $invoice_amountss = $this->getInvoiceAmountss();
    $total = 0;
    foreach($invoice_amountss as $invoice_amounts){
      $total += $invoice_amounts->getSubTotal();
    }
    return $total;
  }
  
  public function getIssueDate(){
    return $this->getDocument()->getDocumentDate();
  }
  
  public function getInvoiceNumber(){
    return $this->getInvoiceType().'-'.$this->getInvoiceId();
  }
  
  public function getTransactions(){
    $con = Propel::getConnection();
    $transactions = myQuery::getInvoiceTransactions($con,$this->getInvoiceIden());
    $transaction_list = array('PAYMENT'=>0,'DEBIT MEMO'=>0,'CREDIT MEMO'=>0,'OTHERS'=>0,);
    foreach($transactions as $transaction){
      if($transaction['type3'] == 'OR')
        $transaction_list['PAYMENT'] = $transaction['debit'] - $transaction['credit'];
      elseif($transaction['type3'] == 'DEBIT MEMO')
        $transaction_list['DEBIT MEMO'] = $transaction['debit'] - $transaction['credit'];
      elseif($transaction['type3'] == 'CREDIT MEMO')
        $transaction_list['CREDIT MEMO'] = $transaction['debit'] - $transaction['credit'];
      else
        $transaction_list['OTHERS'] = $transaction['debit'] - $transaction['credit'];
    }
    return $transaction_list;
  }
  
}
